<!--
 * @Author: 橘子
 * @Project_description: 表单
 * @Description: 代码是我抄的，不会也是真的
-->

<style lang="scss" scoped>
.form-box {
  padding: 20rpx;
  box-sizing: border-box;

  .form-item-box {
    width: 100%;
    display: flex;
    justify-content: flex-end;
  }
}

.btn {
  padding: 30rpx 0;
  box-sizing: border-box;
}
</style>
<template>
  <!-- 表单 -->
  <view class="form-box">
    <q-navbar title="扫码结果" :isBack="false"></q-navbar>
    <u-form ref="form">
      <u-form-item label="所属地名称" prop="avatarImg" label-width="auto">
        <view class="form-item-box">
          {{ form.deptName }}
        </view>
      </u-form-item>
      <u-form-item label="种植时间" prop="plantTime" label-width="auto">
        <view class="form-item-box">
          {{ day(form.plantTime).format('YYYY-MM-DD') }}
        </view>
      </u-form-item>
      <u-form-item label="收货时间" prop="getTime" label-width="auto">
        <view class="form-item-box">
          {{ day(form.getTime).format('YYYY-MM-DD') }}
        </view>
      </u-form-item>
      <u-form-item label="品类等级" prop="productId" label-width="auto">
        <view class="form-item-box">
          <q-dict-tag :value="form.productId" :options="dict.type.pl_dengji"/>
        </view>
      </u-form-item>
      <u-form-item label="品类" prop="plantMain" label-width="auto">
        <view class="form-item-box">
          {{ form.plantMain|plantMainS(plantMainList) }}
        </view>
      </u-form-item>
      <u-form-item label="收获批次" prop="getBatch" label-width="auto">
        <view class="form-item-box">
          {{ form.getBatch }}
        </view>
      </u-form-item>
      <u-form-item label="农药投入" prop="nyTr" label-width="auto">
        <view class="form-item-box">
          {{ form.nyTr }}
        </view>
      </u-form-item>
      <u-form-item label="批次重量" prop="batchZl" label-width="auto">
        <view class="form-item-box">
          {{ form.nyTr }}
        </view>
      </u-form-item>
      <u-form-item label="是否合格" prop="isHg" label-width="auto">
        <view class="form-item-box">
          {{ form.isHg == 0 ? '合格' : '不合格' }}
        </view>
      </u-form-item>
      <u-form-item label="评级" prop="pingji" label-width="auto">
        <view class="form-item-box">
          {{ form.pingji }}
        </view>
      </u-form-item>
      <u-form-item label="分拣员" prop="fenjianyuan" label-width="auto">
        <view class="form-item-box">
          {{ form.fenjianyuan }}
        </view>
      </u-form-item>
      <u-form-item label="分拣时间" prop="fenjianTime" label-width="auto">
        <view class="form-item-box">
          {{ form.fenjianTime }}
        </view>
      </u-form-item>
      <u-form-item label="加工时间" prop="processingTime" label-width="auto">
        <view class="form-item-box">
          {{ form.processingTime }}
        </view>
      </u-form-item>
      <u-form-item label="加工单位" prop="unit" label-width="auto">
        <view class="form-item-box">
          {{ form.unit }}
        </view>
      </u-form-item>
      <u-form-item label="使用添加剂" prop="additives" label-width="auto">
        <view class="form-item-box">
          {{ form.additives }}
        </view>
      </u-form-item>
      <u-form-item label="包裹重量" prop="weight" label-width="auto">
        <view class="form-item-box">
          {{ form.weight }}
        </view>
      </u-form-item>
    </u-form>
  </view>
</template>

<script>
import day from 'dayjs'
import api from '@/api/modules/yuanshi.api'

export default {
  dicts: ['pl_dengji'],
  name: 'form',
  data() {
    return {
      form: {},
      plantMainList: [],
    }
  },
  filters: {
    plantMainS(val, plantMainList) {
      if (!val) return ''
      try {
        let item = plantMainList.find(item => item.merchandiseId == val)
        return item.merchandiseName
      } catch (e) {
        console.log(e)
        return ''
      }
    }
  },
  methods: {
    day,
    async getDetail(id) {
      let res = await api.getYuanshi(id)
      this.form = res.data
    },
    //类型
    async getTypeList() {
      let res = await api.listGoods({
        pageNum: 1,
        pageSize: 10000,
        categoryId: 'ltpivjjw-1d3ufgyz-hsuwll-0000001',
      })
      this.plantMainList = res.data.rows
    },
  },
  /*uni方法*/
  async onLoad(options) {
    await this.getTypeList()
    await this.getDetail(options.id)
  },
  onReady() {
    this.$refs.form.setRules(this.rules);
  },
}
</script>
